let express = require('express');
let router = express.Router();
let mongoose = require('mongoose');
let stuModel = require('../models/swipe');


//连接数据库
// mongoose.connect('mongodb://127.0.0.1:27017/demo',{useNewUrlParser: true });

// mongoose.connection.once('connected', () => {
//  console.log("数据库连接成功")
// });

// mongoose.connection.on('error', () => {
//   console.log("MongoDB connected fail")
//  });

//  mongoose.connection.on('disconnected', () => {
//   console.log("MongoDB connected disconnected")
//  });
//插入
//  stuModel.create({
//   name: "白骨精",
//   age: 26,
//   gender:"",
//   aderss:"白骨洞"
// }, function(err){
//   if(!err){
//     console.log("插入成功");
//   }
// })
//更新
// stuModel.updateOne({name:"白骨精"},{$set:{gender:"female"}},function(err){
//   if(!err){
//     console.log("修改成功")
//   }
// })
 router.get("/", function(req, res, next) {
  stuModel.find({},function(err,docs){
  if(!err){
    res.json({
      docs
    })
  }
  })
 
 })

 module.exports = router;